package com.wenwu.common.utils;

import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.Map;

import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger;

import com.wenwu.common.bean.RelicsProtectArea;

public class CreateRelicsProtectAreaBean {


	public static RelicsProtectArea creatConfiguration(RelicsProtectArea relicsProtect,String data){
		if (StringUtils.isNotEmpty(data)) {
			String[] datas = data.split("&");
			String[] strs = null;
			HashMap<String, String> map = new HashMap<String, String>();
			for (String str : datas) {
				if (StringUtils.isNotEmpty(str)) {
					strs = str.split("=");
					if (strs.length == 2) {
						map.put(strs[0], strs[1]);
					}
				}
			}
			//主键basicId
			if (StringUtils.isNotEmpty(map.get("protectId"))) {
				relicsProtect.setProtectId(Integer.parseInt(map.get("protectId")));
			}
			if (StringUtils.isNotEmpty(map.get("basicId"))) {
				relicsProtect.setBasicId(Integer.parseInt(map.get("basicId")));
			}
			if (StringUtils.isNotEmpty(map.get("basicName"))) {
				relicsProtect.setBasicName(map.get("basicName"));
			}
			relicsProtect.setDevelopProjectSituation(map.get("developProjectSituation"));
			//保护组织
			if (StringUtils.isNotEmpty(map.get("protectOrgan"))) {
				relicsProtect.setProtectOrgan(Integer.parseInt(map.get("protectOrgan")));
			}
			relicsProtect.setProtectFlag(map.get("protectFlag"));
			relicsProtect.setSecureWorkSituation(map.get("secureWorkSituation"));
			relicsProtect.setSecureProtectOrgan(map.get("secureProtectOrgan"));
			relicsProtect.setMonitorInstallation(map.get("monitorInstallation"));
			relicsProtect.setGuardInstallation(map.get("guardInstallation"));
			relicsProtect.setFireInstallation(map.get("fireInstallation"));
			relicsProtect.setFile(map.get("file"));			
		}
		return relicsProtect;
	}
	
	public static Map getValue(Object thisObj)
	  {
	    Map map = new HashMap();
	    Class c;
	    try
	    {
	      c = Class.forName(thisObj.getClass().getName());
	      Method[] m = c.getMethods();
	      for (int i = 0; i < m.length; i++)
	      {
	        String method = m[i].getName();
	        if (method.startsWith("get"))
	        {
	          try{
	          Object value = m[i].invoke(thisObj);
	          if (value != null)
	          {
	            String key=method.substring(3);
	            key=key.substring(0,1).toUpperCase()+key.substring(1);
	            map.put(method, value);
	          }
	          }catch (Exception e) {
	            // TODO: handle exception
	            System.out.println("error:"+method);
	          }
	        }
	      }
	    }
	    catch (Exception e)
	    {
	      // TODO: handle exception
	      e.printStackTrace();
	    }
	    return map;
	  }
}
